package cn.manjuu.touhou.db.dao;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import cn.manjuu.touhou.APP;
import cn.manjuu.touhou.db.ToHoDBOpenHelper;
import cn.manjuu.touhou.domain.Drama;
import cn.manjuu.touhou.domain.Drama;
import cn.manjuu.touhou.interfaces.IConstantValues;
import cn.manjuu.touhou.manager.AssetsDatabaseManager;
import cn.manjuu.touhou.util.Looger;

public class DramaDao {

	private static final String TABLE = "drama";
	public static final String _ID = "_id";
	public static final String INDEXS = "indexs";
	public static final String CONTENT = "content";
	public static final String IMAGE = "image";
	public static final String THEME = "theme";
	private AssetsDatabaseManager mg;

	public DramaDao(Context context) {
		super();
		init();
	}

	private void init() {
		mg = AssetsDatabaseManager.getManager();
	}

	public List<Drama> queryAllOrderIndex(String key, Object value) {
		// TODO Auto-generated method stub
		SQLiteDatabase db = mg.getDatabase("drama.db");
		List<Drama> dramas = null;
		if (db.isOpen()) {
			Cursor c = db.query(TABLE, null, key + "=?", new String[] { value
					+ "" }, null, null, INDEXS);
			Drama drama = null;
			dramas = new ArrayList<Drama>();
			while (c.moveToNext()) {
				drama = new Drama();
				drama.setContent(c.getString(c.getColumnIndex(CONTENT)));
				drama.setImage(c.getString(c.getColumnIndex(IMAGE)));
				drama.setIndex((c.getLong(c.getColumnIndex(INDEXS))));
				drama.setTheme((c.getString(c.getColumnIndex(THEME))));
				Looger.i(APP.DramaDao, drama.toString());
				dramas.add(drama);
				drama = null;
			}
			c.close();
			mg.closeDatabase("drama.db");
		}
		return dramas;
	}
}
